﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PwdMgr.CommonContract;
using PwdMgr.Utility;

namespace PwdMgr.PwdMgrService.Sessions
{
    class SessionMgr
    {
        static SessionMgr()
        {
            _sessions = new Dictionary<string, Session>();
        }

        private static IDictionary<string, Session> _sessions;
        public static Session CreateSession(UserInfo user)
        {
            Session session = new Session
            {
                SessionID = Guid.NewGuid().ToString(),
                Username = user.UserName,
            };
            session.UID = user.UserID;

            _sessions.Add(session.SessionID, session);

            return session;
        }

        public static Session FindBySessionID(string sessionID)
        {
            ThrowUtil.ArgumentNullException(sessionID);

            if (_sessions.ContainsKey(sessionID))
                return _sessions[sessionID];

            return null;
        }
    }
}
